package com.example.demo.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.annotation.SystemAdmin;
import com.example.demo.dto.PageDTO;
import com.example.demo.dto.ServiceAddDTO;
import com.example.demo.mapper.ServiceMapper;
import com.example.demo.pojo.Service;
import com.example.demo.service.ServiceService;
import com.example.demo.utils.RedisIdWorker;
import jakarta.annotation.Resource;

import java.util.List;


@org.springframework.stereotype.Service
public class ServiceServiceImpl extends ServiceImpl<ServiceMapper, Service> implements ServiceService {
    @Resource
    private RedisIdWorker redisIdWorker;
    @Override
    public void addService(ServiceAddDTO serviceAddDTO) {
        Service service = BeanUtil.copyProperties(serviceAddDTO, Service.class);
        service.setId(redisIdWorker.nextId("service"));
        save(service);
    }

    @Override
    public List<Service> getServiceList(PageDTO pageDTO) {
        Integer page = pageDTO.getPage();
        Integer pageSize = pageDTO.getPageSize();
        String sortFiled = pageDTO.getSortFiled();

        Page<Service> p = Page.of(page, pageSize);
        p.addOrder(new OrderItem("id", false));
        lambdaQuery().page(p);

        return p.getRecords();
    }
}
